<template>
  <div class="container">
    <div class="top">
      <div class="icon"><img src="../assets/img/logo2.png" alt=""></div>

      <div class="search" @click="toSreach">
        <span></span>搜索商品名称
      </div>

      <div class="icon1">
        <img src="../assets/img/pc.png" alt="">
      </div>

    </div>

    <main class="main">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white" v-if="banner">
        <van-swipe-item v-for="(item, index) in banner.data" :key="index"><img :src="item.bannerImg" :alt="item.remark">
        </van-swipe-item>
      </van-swipe>
    </main>

    <div class="conter">
      <ul>
        <li>
          <img src="../assets/img/bi.png" alt="">
          <p>游戏币</p>
        </li>

        <router-link to="/buy" tag="li">
          <img src="../assets/img/user.png" alt="">
          <p>账号</p>
        </router-link>

        <li>
          <img src="../assets/img/phoneGo.png" alt="">
          <p>手机充值</p>
        </li>
        <li>
          <img src="../assets/img/dailian.png" alt="">
          <p>代练</p>
        </li>


        <router-link to="/buy" tag="li">
          <img src="../assets/img/user.png" alt="">
          <p>装备</p>
        </router-link>
      </ul>
    </div>

    <div class="listst">
      <div class="title">
        <div :class="['left', indexs == 0 ? 'con' : '']" @click="indexs = 0">
          <span></span>
          <p>热门手游</p>
        </div>
        <div :class="['right', indexs == 1 ? 'con' : '']" @click="indexs = 1">
          <span></span>
          <p>热门端游</p>
        </div>
      </div>
      <div class="center" v-if="phoneGame">
        <ul v-if="indexs == 1">
          <router-link to="/buy" tag="li" v-for="(item, index) in computerGame" :key="index">
            <img :src="item.gameImageUrl" alt="">
            <p>{{ item.name }}专区</p>
          </router-link>
        </ul>

        <ul v-if="indexs == 0">
          <router-link to="/buy" tag="li" v-for="(item, index) in phoneGame.data" :key="index">
            <img :src="item.gameImageUrl" alt="">
            <p>{{ item.name }}专区</p>
          </router-link>
        </ul>

      </div>
      <router-link to="/buy" tag="div" class="move">更多游戏</router-link>
    </div>

    <div class="index-record">
      <div class="title">热门推荐</div>

      <ul v-if="hotGame">
        <li v-for="(item, index) in hotGame.data" :key="index">
          <div class="listsa">
            <div class="lefts">
              <img :src="item.gameImage" alt="">
              <p>精品账号</p>
            </div>
            <div class="right">
              <p>{{ item.gameName }}精品账号</p>
              <p>{{ item.latestInformation }}</p>
              <p>全区全服</p>
            </div>
            <div class="next"><img src="../assets/img/mbgmes-ico.png" alt=""></div>
          </div>
        </li>
      </ul>


    </div>

    <div class="bottom-btn">

    </div>
    <bottom-com></bottom-com>
  </div>
</template>

<script>
import { getBanner, getPhoneGame, getcomputerGame, getHotGame, getData } from "../assets/api/home.js"
export default {
  data() {
    return {
      banner: null,
      phoneGame: null,
      computerGame: null,
      hotGame: null,
      indexs: 0,
      gameData: null,

    };
  },
  methods: {
    //轮播图
    getBannerfun() {
      getBanner().then((data) => {
        this.banner = data.data
        console.log(this.banner.data);
      })
    },
    //手机游戏
    getPhoneGameFun() {
      getPhoneGame().then((data) => {
        this.phoneGame = data.data
        console.log(this.phoneGame);
      })
    },
    getcomputerGameFun() {
      getcomputerGame().then((data) => {
        this.computerGame = data.data.data
        console.log(data.data.data);
      })
    },

    //热门推荐
    getHotGameFun() {
      getHotGame().then((data) => {
        this.hotGame = data.data
        console.log(this.hotGame);
      })
    },
    getDataFun() {
      getData().then((data) => {
        this.gameData = data.data
        console.log(this.gameData);

        //存储本地
        window.localStorage.setItem("gameData", JSON.stringify(this.gameData));

        console.log(JSON.parse(window.localStorage.getItem("gameData")));
      })
    },
    toSreach() {
      console.log("跳转到搜索页面");
      this.$router.push({
        path: '/seach',
        query: {
          gameData: this.gameData
        }
      })
    }


  },
  components: {
    bottomCom: () => import('../components/bottomCom.vue')
  },

  created() {
    //轮播图
    this.getBannerfun()
    //手机游戏
    this.getPhoneGameFun()
    //热门推荐
    this.getHotGameFun()

    this.getcomputerGameFun()

    this.getDataFun()
  },

}
</script>

<style lang="scss">
@import "../assets/css/base.css";

.top {
  width: 100%;
  height: 40px;
  background-color: #ff6600;
  display: flex;
  align-items: center;

  .icon {
    width: 17.3%;
    margin-left: 5px;
    margin-right: 5px;
    text-align: center;
  }

  .icon1 {
    width: 11.3%;
    margin-right: 5px;
    text-align: center;
  }

  .search {
    background-color: #ffffff;
    height: 30px;
    line-height: 30px;
    color: #c9c9c9;
    flex: 1;
    font-size: 11px;
    text-align: center;

    span {
      padding-left: 16px;
      height: 14px;
      background: url(../assets/img/下载.png)no-repeat center center;
      background-size: 100%;
    }
  }
}

.main {
  position: relative;
  width: 100%;

  img {
    height: 154px;
  }
}

.conter {
  height: 96px;
  background-color: #fff;
  display: flex;
  align-items: center;

  ul {
    width: 100%;
    display: flex;
    justify-content: space-around;

    li {
      width: 50px;
      text-align: center;
      font-size: 11px;
    }
  }
}

.listst {
  margin-top: 8px;
  background-color: #ffffff;

  .title {
    height: 43px;
    display: flex;

    .left {
      width: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      border: 1px solid #ececec;
      font-size: 12px;
      background-color: #f8f8f8;
      border-right: none;

      p {
        padding-left: 20px;
        background: url(../assets/img/shouji.png)no-repeat 0 center;
        background-size: 20%;
      }
    }

    .right {
      width: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      border: 1px solid #ececec;
      font-size: 12px;
      background-color: #f8f8f8;

      p {
        padding-left: 20px;
        background: url(../assets/img/diannao-gray.png)no-repeat 0 center;
        background-size: 20%;
      }
    }

    .con {
      color: #ff6600;
      background-color: #Fff;
    }
  }

  .center {
    ul {
      margin-top: 18px;
      display: flex;
      width: 100%;
      justify-content: space-around;
      flex-wrap: wrap;

      li {
        width: 21%;
        margin-top: 20px;
        text-align: center;
        display: flex;
        flex-direction: column;
        align-items: center;

        img {
          width: 62px;
          height: 62px;
          border-radius: 10px;
        }

        p {
          width: 60px;
          font-size: 11px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
    }
  }
}

.move {
  height: 40px;
  line-height: 40px;
  text-align: center;
  margin: 8px 0 8px 0;
  border-top: 2px solid #f1f1f1;
  font-size: 11px;
  color: #666666;
}

.index-record {
  background-color: #fff;
  padding-bottom: 48px;

  .title {
    width: 100%;
    height: 50px;
    line-height: 50px;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    color: #251e25;
  }

  ul {
    li {
      height: 109px;
      border-bottom: 1px solid #f7f7f7;

      .listsa {
        padding: 14px 9px;
        display: flex;
        position: relative;

        .next {
          width: 16px;
          height: 30px;
          position: absolute;
          top: 0px;
          right: 10px;
          bottom: 0px;
          margin: auto;
        }

        .lefts {
          width: 62px;
          height: 62px;
          border-radius: 9px;
          display: flex;
          position: relative;

          img {
            border-radius: 9px;
            width: 100%;
            height: 100%;
          }

          p {
            font-size: 12px;
            color: #fff;
            width: 100%;
            text-align: center;
            background-color: rgba(0, 0, 0, 0.5);
            position: absolute;
            bottom: 0px;
            left: 0px;
            border-bottom-right-radius: 9px;
            border-bottom-left-radius: 9px;
          }


        }

        .right {
          padding-left: 15px;
          display: flex;
          flex-direction: column;
          justify-content: space-around;

          p {
            &:nth-child(1) {
              color: #010507;
              font-size: 15px;
              font-weight: 500;
            }

            &:nth-child(2) {
              color: #ff8131;
              font-size: 15px;
            }

            &:nth-child(3) {
              color: #8a8a8a;
              font-size: 13px;
            }
          }
        }
      }
    }
  }
}
</style>